﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib prefix="c"
uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
  <head>
    <link rel="stylesheet" href="${ctx}/common/common.css" />
    <title>Title</title>
    <link rel="stylesheet" href="${ctx}/common/plugins/layuiadmin/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="${ctx}/common/plugins/layuiadmin/style/admin.css" media="all" />
    <script src="${ctx}/common/plugins/layuiadmin/layui/layui.js"></script>
    <style>
      .layui-form-item .layui-input-inline {
        width: 100%;
      }
    </style>
  </head>
  <body>
    <!--主体内容层-->
    <div class="layui-fluid">
      <div class="layui-row layui-col-space15">
        <div class="layui-col-md12 layui-col-space15">
          <form class="layui-form-item">
            <!--输入框内容盒子-->
            <div class="layui-col-md12">
              <!--输入框-->
              <div class="layui-col-md4">
                <label class="layui-form-label">标准编号</label>
                <div class="layui-input-block">
                  <input
                    type="text"
                    name="code"
                    id="code"
                    required
                    lay-verify="required"
                    placeholder="请输入标准编号"
                    autocomplete="off"
                    class="layui-input"
                  />
                </div>
              </div>
              <div class="layui-col-md4">
                <label class="layui-form-label">标准名称</label>
                <div class="layui-input-block">
                  <input
                    type="text"
                    name="name"
                    id="name"
                    required
                    lay-verify="required"
                    placeholder="请输入标准名称"
                    autocomplete="off"
                    class="layui-input"
                  />
                </div>
              </div>
              <div class="layui-col-md4" style="display: flex; align-items: center">
                <label class="layui-form-label">适用产品范围：</label>
                <div class="layui-input-inline">
                  <div class="layui-form-select">
                    <div class="layui-select-title">
                      <input type="hidden" id="productClassifyId" name="productClassifyId" />
                      <input
                        type="text"
                        name="clyname"
                        id="clyname"
                        required
                        lay-verify="required"
                        placeholder="请选择产品范围"
                        autocomplete="off"
                        class="layui-input layui-unselect"
                        readonly="readonly"
                      />
                    </div>
                  </div>
                </div>
                <button id="selectSource" type="button" class="layui-btn layui-btn-sm layui-btn-warm">选择</button>
              </div>
            </div>
            <!--通用按钮盒子-->
            <div class="layui-col-md12" style="padding-top: 10px; padding-bottom: 10px">
              <div class="layui-btn-group demoTable">
                <button class="layui-btn layui-btn-sm" type="button" data-type="addInspect">
                  <i class="layui-icon">&#xe654;</i>
                </button>
                <!--删除-->
                <button class="layui-btn layui-btn-sm" type="button" data-type="delInspect">
                  <i class="layui-icon">&#xe640;</i>
                </button>
              </div>
              <div style="float: right" class="layui-btn-group paramBtn">
                <button data-type="reloadInspectEnt" type="button" class="layui-btn layui-btn-sm layui-btn-danger">
                  查询
                </button>
                <button data-type="resetInspectEnt" type="reset" class="layui-btn layui-btn-sm layui-btn-danger">
                  重置
                </button>
              </div>
            </div>
          </form>
          <!--通用table表格-->

          <table
            class="layui-table"
            id="inspectReload"
            lay-data="{ url:'${ctx }/supervise/inspection/queryInspectionList', page:true,groups:5}"
            lay-filter="demo"
          >
            <thead>
              <tr>
                <th lay-data="{type:'checkbox', fixed: 'left'}"></th>
                <th lay-data="{field:'code'}">编号</th>
                <th lay-data="{field:'name'}">名称</th>
                <th lay-data="{field:'standard_Type'}">类型</th>
                <th lay-data="{field:'described'}">适用产品范围</th>
                <th lay-data="{field:'published_date'}">发布日期</th>
                <th lay-data="{field:'execution_date'}">实施日期</th>
                <th lay-data="{field:'publisher'}">发布机构</th>
                <th lay-data="{field:'right',toolbar:'#barDemo',width:250}">操作</th>
              </tr>
            </thead>
          </table>
        </div>
      </div>
    </div>
    <script type="text/html" id="barDemo">
      <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">详细</a>
      <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
      <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
  </body>
  <script>
    layui.use(["table", "layer"], function () {
      //         var loading=layer.msg("数据加载中...");
      var table = layui.table,
        $ = layui.$, //重点处
        layer = layui.layer;

      if ($("#selectSource").length > 0) {
        document.getElementById("selectSource").addEventListener("click", function () {
          layer.open({
            type: 2,
            skin: "layui-layer-rim", //加上边框
            area: ["80%", "70%"],
            content: "${ctx}/supervise/inspection/selectProductClassify2",
          });
          form.render();
        });
      }

      table.render({
        done: function () {
          layer.close(loading);
        },
      });
      //监听filter为demo的table中的工具条
      table.on("tool(demo)", function (obj) {
        var data = obj.data;
        if (obj.event === "detail") {
          //跳转查看页
          window.location.href = "${ctx}/supervise/inspection/queryInspectView?inspectionId=" + obj.data.id;
        } else if (obj.event === "del") {
          layer.confirm("确认删除?", function (index) {
            obj.del();
            layer.close(index);
            //删除
            $.post(
              "${ctx}/supervise/inspection/delInspect",
              { ids: obj.data.id },
              function (data) {
                if (data == "success") {
                  layer.alert("删除成功");
                  table.reload("inspectReload", {
                    where: {
                      code: "",
                      name: "",
                      productClassifyId: "",
                    },
                  });
                } else {
                  layer.alert("删除失败");
                }
              },
              "text"
            );
          });
        } else if (obj.event === "edit") {
          //新增修改页
          window.location.href = "${ctx}/supervise/inspection/inspectionEdit?inspectionId=" + obj.data.id;
        }
      });

      var $ = layui.$,
        active = {
          reloadInspectEnt: function () {
            //条件查询
            var code = document.getElementById("code").value;
            var name = document.getElementById("name").value;
            var productClassifyId = document.getElementById("productClassifyId").value;
            table.reload("inspectReload", {
              where: {
                code: code,
                name: name,
                productClassifyId: productClassifyId,
              },
            });
          },
          resetInspectEnt: function () {
            table.reload("inspectReload", {
              where: {
                code: "",
                name: "",
                productClassifyId: "",
              },
            });
          },
          addInspect: function () {
            //新增修改页
            window.location.href = "${ctx}/supervise/inspection/inspectAdd";
          },
          delInspect: function () {
            var checkStatus = table.checkStatus("inspectReload");
            var ids = "";
            var ptype = "";
            var data = checkStatus.data;
            for (var i in data) {
              ids += data[i].id + ",";
            }
            if (ids != "" && ids.length > 0) {
              layer.confirm("确认删除?", function () {
                $.post(
                  "${ctx}/supervise/inspection/delInspect",
                  { ids: ids },
                  function (data) {
                    if (data == "success") {
                      layer.alert("删除成功");
                      table.reload("inspectReload", {
                        where: {
                          code: "",
                          name: "",
                          productClassifyId: "",
                        },
                      });
                    } else {
                      layer.alert("删除失败");
                    }
                  },
                  "text"
                );
              });
            } else {
              layer.alert("请选择要删除的信息!");
            }
          },
        };

      $(".demoTable .layui-btn").on("click", function () {
        var type = $(this).data("type");
        active[type] ? active[type].call(this) : "";
      });
      //给按钮绑定active中的方法
      $(".paramBtn .layui-btn").on("click", function () {
        var type = $(this).data("type");
        //查看是active这个json中是否有type这个方法，如果有调用，如果没有不知心；
        active[type] ? active[type].call() : "";
      });
    });
  </script>
</html>
